1. Standard Library Functions
These are predefined functions provided by C libraries. These functions are available for use without needing to define them yourself. They are part of the C Standard Library, which includes functions for performing input and output, mathematical operations, string manipulations, memory allocations, and more.
Some examples of standard library functions are:
- printf() – Used for outputting text to the console.
- scanf() – Used for taking input from the user.
- strlen() – Used to determine the length of a string.
- malloc() – Used for memory allocation.
- abs() – Returns the absolute value of an integer.
2. User-Defined Functions
These are functions that the programmer defines based on the requirements of the program. These functions allow you to break down a large program into smaller, manageable pieces, and they are usually designed to perform specific tasks.
A user-defined function can have:
- Return type: The type of data the function returns (e.g.,
int,float,void). - Function name: The name by which the function is called.
- Parameters: The inputs provided to the function.
Example of a user-defined function:
#include < stdio.h>
// Function declaration
int add(int a, int b);
// Main function
int main() {
int result = add(5, 3);
printf("The sum is: %d\n", result);
return 0;
}
// Function definition
int add(int a, int b) {
return a + b;
}